package com.example.flower_shop.controller.usr;

import com.example.flower_shop.common.PageResult;
import com.example.flower_shop.service.usr.UsrArticleService;
import com.example.flower_shop.vo.article.ArticleRespVO;
import com.example.flower_shop.vo.article.UsrArtPageResp;
import com.example.flower_shop.vo.article.UsrArticlePageReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户文章操作")
@RestController
@RequestMapping("/api/usr/article")
public class ArticleController {

    @Resource
    private UsrArticleService articleService;

    @GetMapping
    @Operation(summary = "获取文章列表", method = "GET")
    public PageResult<UsrArtPageResp> findArticlePage(@Valid UsrArticlePageReq req) {
        return articleService.findArticlePage(req);
    }

    @GetMapping("/{articleId}")
    @Operation(summary = "获取文章详情", method = "GET",
            parameters = {
                    @Parameter(name = "articleId", description = "文章ID", required = true, in = ParameterIn.PATH)
            })
    public ArticleRespVO getArticle(@PathVariable Long articleId) {
        return articleService.getArticle(articleId);
    }
}
